doctype html
html(lang='en')
  head
    meta(charset='utf-8')
    meta(http-equiv='X-UA-Compatible', content='IE=edge')
    meta(name='viewport', content='width=device-width, initial-scale=1')
    meta(name='description', content='')
    meta(name='author', content='')
    link(rel='icon', href='/css/favicon.ico')
    title Sheng's Blogs
    link(href='/components/bootstrap/dist/css/bootstrap.min.css', rel='stylesheet')
    link(href='/css/blog.css', rel='stylesheet')
    link(href="/components/font-awesome/css/font-awesome.min.css", rel='stylesheet')
    block css

  body
    include ./includes/header.jade

    block content

    include ./includes/footer.jade

    .back-to-top
      i.fa.fa-arrow-up

    script(src='/components/jquery/dist/jquery.min.js')
    script(src='/components/bootstrap/dist/js/bootstrap.min.js')
    block scripts
    script(type='text/javascript').
      $(function () {
        $("#searchform").submit(function (e) {
          var value = $('#searchfor').val();

          if (value == '') {
            alert("搜索内容为空");
            return false;
          }
          return true;
        });

        $(window).scroll(function () {
          var top = $(document).scrollTop();
          if(top > 0){
            $(".back-to-top").show();
          }else{
            $(".back-to-top").hide();
          }
        });
        $(".back-to-top").click(function(){
          var speed = 200;//滑动的速度
          $('body,html').animate({scrollTop: 0}, speed);
          return false;
        });

        var adjustFooter = function(){
          $(".middle-main").css("margin-bottom", "50px");


          var pingmu_height = $(window).height(); //浏览器当前窗口可视区域高度
          var document_height = $(document.body).height();

          //console.log(pingmu_height);
          //console.log(document_height);
          if (document_height < pingmu_height) {
            var cheight = pingmu_height - document_height;
            //console.log(cheight);
            var oriheight = $(".middle-main").css("margin-bottom");
            var index = oriheight.indexOf("px");
            var strheight = oriheight.slice(0, index);
            var intheight = parseInt(strheight);
            //console.log(intheight);
            var allheight = intheight + cheight;
            var strallheight = allheight + "px";
            //console.log(strallheight);
            $(".middle-main").css("margin-bottom", strallheight);
          }
        };

        (function () {
          adjustFooter();
        })();

        $(window).resize(function () {
          adjustFooter();
        });
      });
